<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>异常订单</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <%--<form id="searchFormAbnormal" action="${basePath}/all_order/excel_export_abnormal.do">--%>
        <div class="screen-search">
            <ul>
                <li>
                    <label>客户姓名：</label>
                    <input type="text" class="dggui-input dggui-input-normal" id="customerName" name="customerName" placeholder="输入客户姓名" maxlength="50">
                </li>
                <li>
                    <label>接单时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="receiveOrderDate" name="receiveOrderDate">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>流程人员：</label>
                    <select id="flowUserId" name="flowUserId"  style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>所属生产事业部：</label>
                    <input type="hidden" id="productOrgIdHidden">
                    <select id="productOrgId" name="productOrgId" >
                    </select>
                </li>
                <li>
                    <label>签单商务：</label>
                    <select  id="signUserId" name="signUserId">
                    </select>
                </li>
                <li>
                    <label>签单部门：</label>
                    <div class="tree-select-warp">
                        <input type="text" class="dggui-input input-selct-tree" id="signOrg" name="signOrg"  data-id="" value="" style="width: 320px" />
                    </div>
                </li>
                <li>
                    <label>订单状态：</label>
                    <select name="orderStatus" id="orderStatus" style="min-width: 80px; display: none;">
                    </select>
                </li>
             <%--   <li>
                    <label>业务类型：</label>
                    <div name="typeCode" id="typeCode"></div>
                </li>
                <li>
                    <label>产品：</label>
                    <select name="productCode" id="productCode" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>渠道：</label>
                    <select name="channelCode" id="channelCode" class="dggui-select">
                        <option value=''>请选择</option>
                    </select>
                </li>--%>

          <%--      <li>
                    <label>签单时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="signTime" name="signTime">
                    <i class="iconfont icon-rili"></i>
                </li>--%>

                <li>
                    <label>关键字：</label>
                    <input type="text" class="dggui-input dggui-input-large" id="searchKey" name="searchKey" placeholder="订单编号/生产单编号/客户号码" maxlength="50" style="width: 190px;">
                </li>
         <%--       <li>
                    <label>需求金额：</label>
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMin" name="moneyMin" placeholder="输入最小金额" min="0">~
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMax" name="moneyMax" placeholder="输入最大金额" min="0">
                </li>--%>
                <li>
                    <button class="dggui-btn searchBtn" onclick="tableReload();return false;">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                    <button class="dggui-btn dggui-btn-green" onclick="excelExportAbnormal('${basePath}/all_order/excel_export_abnormal.do');return false;">导出</button>
                    </d:hasUrlAuth>
                </li>
            </ul>
        </div>
       <%-- </form>--%>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <d:hasUrlAuth authCode="RZSC_OPERATION_CALL">
                <a href="javascript:void(0)" class="dggui-btn" onclick="callPhoneByProduction($('#allOrderList'))">打电话</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_TRANSFER">
                <a href="javascript:void(0)" class="dggui-btn" onclick="turnoverProductOrder('#allOrderList','')">移交</a>
                </d:hasUrlAuth>
            </div>
            <div class="fr node-state" >
                <ul>
                    <li class="over-finish">订单超期</li>
                    <li>节点超期</li>
                </ul>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="allOrderList">
            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var NORMAL = '${NORMAL}', TIME_OUT = '${TIME_OUT}';
    var tables;
    var index;
    dggui.use(['table', 'select2','distpicker','dggdate','droptree'], function (){
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree = dggui.droptree;
        // 加载部门下拉框
        queryAllDep("#signOrg");
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
           placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "160px"
        });
        //初始化订单状态
        commonTreeBookCode("#orderStatus", "RZSCORDER_STATUS", 1, 1, 1, true);
        select2.render({
           placeholder: "请选择",
            allowClear: true,
            elem: $('#orderStatus'),
            width: "160px"
        });
        <%--select2.render({--%>
           <%--placeholder: "请选择",--%>
            <%--allowClear: true,--%>
            <%--elem: $('#productCode'),--%>
            <%--width: "160px"--%>
        <%--});--%>
        <%--//初始化业务类型及产品--%>
        <%--distpicker.render({--%>
            <%--url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址--%>
            <%--elem: '#typeCode', // 容器Id--%>
            <%--type: 2,--%>
            <%--placeholder: '选择业态',--%>
            <%--defaultParentCode:'BUS_YT_DK',--%>
            <%--callback:function () {//如果不需要选产品就把callback整个方法注释掉--%>
                <%--var code = $("#typeCode .plug-in-code").val();--%>
                <%--initProductCode("#productCode",code);--%>
                <%--select2.render({--%>
                   <%--placeholder: "请选择",--%>
                    <%--allowClear: true,--%>
                    <%--elem: $('#productCode'),--%>
                    <%--width: "160px"--%>
                <%--});--%>
                <%--var produtId = $("#productCode").val();--%>
                <%--initChannel("#channelCode",produtId);--%>
                <%--select2.render({--%>
                    <%--placeholder: "请选择",--%>
                    <%--allowClear: true,--%>
                    <%--elem: $('#channelCode'),--%>
                    <%--width: "160px"--%>
                <%--});--%>
            <%--},--%>
            <%--callbackClear:function () {--%>
                <%--$("#productCode").find("option").remove();--%>
                <%--$("#productCode").append("<option value=''>请选择</option>");--%>
                <%--$("#channelCode").find("option").remove();--%>
                <%--$("#channelCode").append("<option value=''>请选择</option>");--%>
            <%--}--%>
        <%--});--%>
        <%--//渠道初始化--%>
        <%--$('#productCode').on('change', function (e) {--%>
            <%--var produtId = $("#productCode").val();--%>
            <%--initChannel("#channelCode",produtId);--%>
            <%--select2.render({--%>
               <%--placeholder: "请选择",--%>
                <%--allowClear: true,--%>
                <%--elem: $('#channelCode'),--%>
                <%--width: "160px"--%>
            <%--});--%>
        <%--});--%>
        //初始化已离职流程人员
        initUserDimission("RZSC_FLOW_USER","role","#flowUserId",2);
        select2.render({
           placeholder: "请选择",
            allowClear: true,
            elem: $('#flowUserId'),
            width: "160px"
        });
        //初始化签单商务
        initUser("RZSC_SIGN_USER","role","#signUserId");
        select2.render({
           placeholder: "请选择",
            allowClear: true,
            elem: $('#signUserId'),
            width: "160px"
        });
        //初始化签单时间
     /*   dggdate.render({
            elem: '#signTime',
            type: 'date',
            range: '~'
        });*/
        //初始化接单时间
        dggdate.render({
            elem: '#receiveOrderDate',
            type: 'date',
            range: '~'
        });
        //初始化签单商务
        initUser("bus_advisor","role","#signUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#signUserId'),
            width: "160px"
        });
        var opt={
            "elem":"#allOrderList",
            "ajax": sysInfo.basePath +"/all_order/all_Order_json.do",
            "scrollX": "true",//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "fnServerParams": function (aoData) {
                // var moneyMax = $("#moneyMax").val().trim();
                // var moneyMin = $("#moneyMin").val().trim();
                //搜索条件
                aoData = $.extend(aoData, {
                        // customerPhone:$("#customerPhone").val(),
                        productOrgId:$("#productOrgId").val(),
                        statusAttr:$("#orderStatus").val(),
                        // typeCode:$("#typeCode .plug-in-code").val(),
                        // productId:$("#productCode").val(),
                        // channelId:$("#channelCode").val(),
                        flowUserId:$("#flowUserId").val(),
                        // orderTime:$("#signTime").val(),
                        receiveOrderDate:$("#receiveOrderDate").val(),
                        searchKey:$("#searchKey").val(),
                        userLocked:'2',
                        customerName:$("#customerName").val(),
                        signOrgOrBusId:$("#signOrg").attr("data-id"),
                        signUserId:$("#signUserId").val(),
                    /*    moneyMax:moneyMax,
                        moneyMin:moneyMin,*/
                    }
                )
                return aoData;
            },
            "aoColumns": [
                {
                    "sClass": "check-th",
                    "title": '<input type="checkbox" class="checkall">',
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                    }
                },
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    "title": "所属生产事业部",
                    "data": "productOrgName",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "订单编号",
                    "orderable": false,
                    "data": "orderNo",
                    "render": function (data, type, full, meta) {
                        return ('<a href=\'javascript:void(0)\' class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                       /* return data;*/
                    }
                },
                {
                    "title": "生产订单编号",
                    "orderable": false,
                    "data": "scProductOrderNo",
                    "render": function (data, type, full, meta) {
                        var result = "";
                        result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><span>' + data + '</span></a>';
                        return result;
                    }
                },
                {
                    "title": "客户",
                    "orderable": false,
                    "data": "customerName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.customerName) + '<p>' + emptyStringConvert(full.customerPhone) + '</p>';
                    }
                },
                {
                    "title":"合同编号",
                    "orderable": false,
                    "data": "contractNo",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"订单状态",
                    "orderable": false,
                    "data": "status",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"当前完成节点",
                    "orderable": false,
                    "data": "latestEndNodeName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.latestEndNodeName) + '<p>' + emptyStringConvert(full.latestEndNodeTime) + '</p>';
                    }
                },
               /* {
                    "title":"最新备注时间",
                    "orderable": false,
                    "data": "lastRemarkTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },*/
                {
                    "title":"业务类型",
                    "orderable": false,
                    "data": "businessProductName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"产品",
                    "orderable": false,
                    "data": "productName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"渠道",
                    "orderable": false,
                    "data": "channelName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"流程人员",
                    "orderable": false,
                    "data": "flowUserName",
                    "render": function (data, type, full, meta) {
                        return data ? data+'<p>'+emptyStringConvert(full.flowUserOrgName)+'</p>': '';
                    }
                },
                {
                    "title":"签单时间",
                    "orderable": false,
                    "data": "orderTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"接单时间",
                    "orderable": false,
                    "data": "receiveOrderDate",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"签单商务/部门",
                    "orderable": false,
                    "data": "signUserName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.signUserName) + '<p>' + emptyStringConvert(full.signUserOrgName) + '</p>';
                    }
                },
                /*{
                    "title":"签单部门",
                    "orderable": false,
                    "data": "signUserOrgName",
                    "render": function (data, type, full, meta) {
                        //return data+'<p>'+full.signUserOrgName+'</p>';
                        return data;
                    }
                },*/
                {
                    "title":"需求金额（元）",
                    "orderable": false,
                    "data": "loanAmount",
                    "render": function (data, type, full, meta) {
                        var htm = '<div class="order-render">' +
                        '<p><span >' +data ? data : '' + '</span></p>'+
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '最新备注',
                    'data': "lastRemark",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return '<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>' + '<p>'+emptyStringConvert(row.lastRemarkTime)+'</p>';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<a href="javascript:void(0)" class="dggui-link" onclick="remarkOrder(\''+row.id+'\',$(\'#allOrderList\'));">备注</a>';
                        return htm;
                    }
                }
            ],
            "columnDefs": [{
                targets: [3], //第1，2，3列
                createdCell: function (td, cellData, rowData, row, col) {
                    if (rowData.orderTimeStatus == TIME_OUT) {
                        $(td).parent().addClass("red");//订单超期
                        return;
                    } else if (rowData.nodeTimeStatus == TIME_OUT) {//节点超期
                        $(td).parent().addClass("green");
                        return;
                    }
                }
            }]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
           // dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
           if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });

    /**
     * @describe: TODO 获取table选择
     * @author: cuipeng
     * @creat_date: 2018/12/18  15:28
     **/

   function turnoverProductOrder(tableid,id){
        var ids = "";
       if (null != tableid && "" != tableid){
            ids = getChecked(tableid);
       }else {
           ids = id;
       }
       if (ids.length < 1) {
           dggui.dialog.errors('请至少选择一条数据！');
           return;
       }
       var id = getIds(ids);
       dggui.dialog.loading();
       $.ajax({
           url: sysInfo.basePath + '/all_order/layer_turnover_abnormal.html',
           dataType: 'html',
           data:{ids:id},
           success: function (html) {
               dggui.dialog.loading('close');
              index = dggui.dialog.open({
                   title: '是否确认移交选中的订单？',
                   content: html,
                   area: '500px',
                   btn: ["确定", "取消"],
                   yes: function () {
                       sureTurnover(tableid,index);
                   }, btn2: function () {
                   }
               })
           }
       });
   }

    /**
     * 导出
     * */
    function excelExportAbnormal(url) {
  /*      var moneyMax = $("#moneyMax").val().trim();
        var moneyMin = $("#moneyMin").val().trim();
        if(!checkMoneySearch(moneyMin,moneyMax)){
            return;
        }*/
        var obj = new Object();
        // obj.customerPhone= $("#customerPhone").val();
        obj.productOrgId= $("#productOrgId").val();
        // obj.typeCode= $("#typeCode").find(".plug-in-code").val();
        // obj.productId= $("#productCode").val();
        // obj.channelId=$("#channelCode").val();
        // obj.orderTime=$("#signTime").val();
        obj.receiveOrderDate=$("#receiveOrderDate").val();
        obj.searchKey=$("#searchKey").val();
        obj.flowUserId=$("#flowUserId").val();
        obj.statusAttr=$("#orderStatus").val();
        obj.customerName=$("#customerName").val();
        obj.signUserId=$("#signUserId").val();
        obj.signOrgOrBusId=$("#signOrg").attr("data-id");
      /*  obj.moneyMax=moneyMax;
        obj.moneyMin=moneyMin;*/
        formSubmit(url, obj);
    }
    //列表刷新
    function tableReload() {
      /*  var moneyMax = $("#moneyMax").val().trim();
        var moneyMin = $("#moneyMin").val().trim();
        if(!checkMoneySearch(moneyMin,moneyMax)){
            return false;
        }*/
        tables.ajax.reload();
    }
</script>
</body>
</html>